www.gusucode.com > VC++ 在线考试系统,AccessMSSQL-源码程序 > VC++ 在线考试系统,AccessMSSQL-源码程序\code\OnlineTestDlg.cpp
// OnlineTestDlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "OnlineTest.h" #include "OnlineTestDlg.h" #include "USER.h" #include "YHDL.h" #include "YHZC.h" #include "JSDL.h" #include "HTGL.h" #include "ZXKS.h" #include "CJCX.h" #include "ZXDY.h" #include "DAJX.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CUSER theUser; ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // COnlineTestDlg dialog COnlineTestDlg::COnlineTestDlg(CWnd* pParent /*=NULL*/) : CDialog(COnlineTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(COnlineTestDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void COnlineTestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(COnlineTestDlg) DDX_Control(pDX, IDC_TAB_Test, m_TestTab); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(COnlineTestDlg, CDialog) //{{AFX_MSG_MAP(COnlineTestDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_TIMER() ON_COMMAND(ID_MENU1_XXXG, OnMenu1Xxxg) ON_COMMAND(ID_MENU1_CJCX, OnMenu1Cjcx) ON_COMMAND(ID_MENU1_CKGG, OnMenu1Ckgg) ON_COMMAND(ID_MENU1_DAJX, OnMenu1Dajx) ON_COMMAND(ID_MENU1_TCXT, OnMenu1Tcxt) ON_COMMAND(ID_MENU1_ZXDY, OnMenu1Zxdy) ON_COMMAND(ID_MENU1_ZXKS, OnMenu1Zxks) ON_WM_CONTEXTMENU() ON_COMMAND(ID_MENU1_SYBZ, OnMenu1Sybz) ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_Test, OnSelchangeTABTest) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // COnlineTestDlg message handlers BOOL COnlineTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here CYHDL yhdlDlg; // yhdlDlg.Dlg=this; if (yhdlDlg.DoModal()!=IDOK) OnOK(); else if (theUser.u_Power=="学生") XSDL(); else if (theUser.u_Power=="老师") { CJSDL JsdlDlg; JsdlDlg.DoModal(); OnOK(); } else { CHTGL HtglDlg; HtglDlg.DoModal(); OnOK(); } return TRUE; // return TRUE unless you set the focus to a control } void COnlineTestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void COnlineTestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR COnlineTestDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void COnlineTestDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default time=CTime::GetCurrentTime(); CString str="当前时间: 20"; str+=time.Format("%y-%m-%d"); str+=time.Format(" %H:%M:%S"); m_StatusBar.SetText(str,0,2); CDialog::OnTimer(nIDEvent); } void COnlineTestDlg::OnMenu1Xxxg() { // TODO: Add your command handler code here CYHZC dlg; dlg.m_Change=TRUE; dlg.DoModal(); } void COnlineTestDlg::OnMenu1Cjcx() { // TODO: Add your command handler code here CCJCX dlg; dlg.DoModal(); } void COnlineTestDlg::OnMenu1Ckgg() { // TODO: Add your command handler code here CRect rect; m_TestTab.GetClientRect(rect); rect.DeflateRect(1,17,2,2); HysyDlg.ShowWindow(SW_HIDE); SybzDlg.ShowWindow(SW_HIDE); CkggDlg.ShowWindow(SW_HIDE); CkggDlg.MoveWindow(rect); CkggDlg.ShowWindow(SW_SHOW); m_TestTab.SetCurSel(1); } void COnlineTestDlg::OnMenu1Dajx() { // TODO: Add your command handler code here CDAJX dlg; dlg.DoModal(); } void COnlineTestDlg::OnMenu1Tcxt() { // TODO: Add your command handler code here if (MessageBox("您确定要退出系统吗?","系统提示",MB_YESNO)==IDYES) { KillTimer(1); OnOK(); } } void COnlineTestDlg::OnMenu1Zxdy() { // TODO: Add your command handler code here CZXDY dlg; dlg.DoModal(); } void COnlineTestDlg::OnMenu1Zxks() { // TODO: Add your command handler code here CZXKS dlg; dlg.DoModal(); } void COnlineTestDlg::OnContextMenu(CWnd* pWnd, CPoint point) { // TODO: Add your message handler code here CRect rect; GetClientRect(&rect); CMenu menu; menu.LoadMenu(IDR_MENU1); CMenu *pContextMenu=menu.GetSubMenu(0); GetCursorPos(&point); pContextMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x,point.y,this,&rect); menu.DestroyMenu(); } void COnlineTestDlg::OnMenu1Sybz() { // TODO: Add your command handler code here CRect rect; m_TestTab.GetClientRect(rect); rect.DeflateRect(1,17,2,2); HysyDlg.ShowWindow(SW_HIDE); SybzDlg.ShowWindow(SW_HIDE); CkggDlg.ShowWindow(SW_HIDE); SybzDlg.MoveWindow(rect); SybzDlg.ShowWindow(SW_SHOW); m_TestTab.SetCurSel(2); } void COnlineTestDlg::OnSelchangeTABTest(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here CRect rect; m_TestTab.GetClientRect(rect); rect.DeflateRect(1,17,2,2); int i=m_TestTab.GetCurSel(); HysyDlg.ShowWindow(SW_HIDE); SybzDlg.ShowWindow(SW_HIDE); CkggDlg.ShowWindow(SW_HIDE); switch(i) { case 0: HysyDlg.MoveWindow(rect); HysyDlg.ShowWindow(SW_SHOW); break; case 1: CkggDlg.MoveWindow(rect); CkggDlg.ShowWindow(SW_SHOW); break; case 2: SybzDlg.MoveWindow(rect); SybzDlg.ShowWindow(SW_SHOW); break; } *pResult = 0; } BOOL COnlineTestDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==13) { OnMenu1Tcxt(); return true; } return CDialog::PreTranslateMessage(pMsg); } void COnlineTestDlg::XSDL() { //状态栏 m_StatusBar.EnableAutomation(); m_StatusBar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,0); int width[]={150,290,500}; m_StatusBar.SetParts(3,&width[0]); m_StatusBar.SetText("华东理工大学",0,0); CString UserName; UserName.Format("当前用户: %s",theUser.u_Name); m_StatusBar.SetText(UserName,0,1); //工具栏 TBBUTTON button[8]; TCHAR *pString; CString string; int nLength; m_ImageList.Create(32,32,ILC_COLOR32|ILC_MASK,0,0); m_ToolBar.EnableAutomation(); m_ToolBar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,1); for (int i=IDI_ICON1;i<=IDI_ICON8;i++) m_ImageList.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(i))); m_ToolBar.SetImageList(&m_ImageList); for (i=0;i<8;i++) { button[i].dwData=0; button[i].fsState=TBSTATE_ENABLED; button[i].fsStyle=TBSTYLE_BUTTON; button[i].iBitmap=i; string.LoadString(i+IDS_STRING1); nLength=string.GetLength()+1; pString=string.GetBufferSetLength(nLength); button[i].iString=m_ToolBar.AddStrings(pString); string.ReleaseBuffer(); } button[0].idCommand=ID_MENU1_XXXG; button[1].idCommand=ID_MENU1_ZXKS; button[2].idCommand=ID_MENU1_CJCX; button[3].idCommand=ID_MENU1_ZXDY; button[4].idCommand=ID_MENU1_DAJX; button[5].idCommand=ID_MENU1_CKGG; button[6].idCommand=ID_MENU1_TCXT; button[7].idCommand=ID_MENU1_SYBZ; m_ToolBar.AddButtons(8,button); button[0].fsStyle=TBSTYLE_SEP; m_ToolBar.InsertButton(6,&button[0]); m_ToolBar.InsertButton(3,&button[0]); m_ToolBar.InsertButton(1,&button[0]); m_ToolBar.AutoSize(); m_ToolBar.SetStyle(TBSTYLE_FLAT|CCS_TOP); //主窗体选项卡 m_TestTab.InsertItem(0,"欢迎使用在线考试系统 "); m_TestTab.InsertItem(1," 查看公告 "); m_TestTab.InsertItem(2," 使用帮助 "); m_TestTab.SetCurSel(0); CRect rect; m_TestTab.GetClientRect(&rect); rect.DeflateRect(1,17,2,2); HysyDlg.Create(IDD_HYSY_DIALOG,&m_TestTab); SybzDlg.Create(IDD_SYBZ_DIALOG,&m_TestTab); CkggDlg.Create(IDD_CKGG_DIALOG,&m_TestTab); HysyDlg.MoveWindow(rect); HysyDlg.ShowWindow(SW_SHOW); CkggDlg.Dlg=this; SetTimer(1,1000,NULL); }